package com.ruoyi.bms.service.impl;

import java.util.List;

import com.ruoyi.bms.domain.BmsUserUpload;
import com.ruoyi.bms.mapper.BmsUserUploadMapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bms.mapper.BmsBooksMapper;
import com.ruoyi.bms.domain.BmsBooks;
import com.ruoyi.bms.service.IBmsBooksService;

/**
 * 书籍信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-11
 */
@Service
@Slf4j
public class BmsBooksServiceImpl implements IBmsBooksService 
{
    @Autowired
    private BmsBooksMapper bmsBooksMapper;

    @Autowired
    private BmsUserUploadMapper bmsUserUploadMapper;


    /**
     * 查询书籍信息
     * 
     * @param id 书籍信息主键
     * @return 书籍信息
     */
    @Override
    public BmsBooks selectBmsBooksById(Long id)
    {
        return bmsBooksMapper.selectBmsBooksById(id);
    }

    /**
     * 查询书籍信息列表
     * 
     * @param bmsBooks 书籍信息
     * @return 书籍信息
     */
    @Override
    public List<BmsBooks> selectBmsBooksList(BmsBooks bmsBooks)
    {
        return bmsBooksMapper.selectBmsBooksList(bmsBooks);
    }

    /**
     * 新增书籍信息
     * 
     * @param bmsBooks 书籍信息
     * @return 结果
     */
    @Override
    public int insertBmsBooks(BmsBooks bmsBooks)
    {
        Long userId = SecurityUtils.getUserId();
        bmsBooks.setCreateTime(DateUtils.getNowDate());
        bmsBooksMapper.insertBmsBooks(bmsBooks);
        BmsUserUpload bmsUserUpload = BmsUserUpload.builder()
                .userId(userId)
                .status(0L)
                .bookId(bmsBooks.getId())
                .build();
        bmsUserUpload.setCreateTime(DateUtils.getNowDate());
        return bmsUserUploadMapper.insertBrsUserUpload(bmsUserUpload);
    }

    /**
     * 修改书籍信息
     * 
     * @param bmsBooks 书籍信息
     * @return 结果
     */
    @Override
    public int updateBmsBooks(BmsBooks bmsBooks)
    {
        bmsBooks.setUpdateTime(DateUtils.getNowDate());
        return bmsBooksMapper.updateBmsBooks(bmsBooks);
    }

    /**
     * 批量删除书籍信息
     * 
     * @param ids 需要删除的书籍信息主键
     * @return 结果
     */
    @Override
    public int deleteBmsBooksByIds(Long[] ids)
    {
        return bmsBooksMapper.deleteBmsBooksByIds(ids);
    }

    /**
     * 删除书籍信息信息
     * 
     * @param id 书籍信息主键
     * @return 结果
     */
    @Override
    public int deleteBmsBooksById(Long id)
    {
        return bmsBooksMapper.deleteBmsBooksById(id);
    }

    @Override
    public List<BmsBooks> userSelectBmsBooksList(BmsBooks bmsBooks) {
        Long userId = SecurityUtils.getUserId();

        return bmsBooksMapper.userSelectBmsBooksList(bmsBooks);
    }

    @Override
    public List<BmsBooks> selectLoadBmsBooksList() {
        Long userId = SecurityUtils.getUserId();
//        List<BmsBooks> bmsBooks = bmsBooksMapper.selectLoadBmsBooksList(userId);

        return null;
    }


}
